package servlet;
import java.io.IOException;
import java.util.Map;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import entity.Book;
public class ChangeCartServlet extends HttpServlet {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		doGet(request, response);
	}
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		String id = request.getParameter("id");
		// 2.得到要修改的数量 
		// 3.从session中获取购物车.
		HttpSession session = request.getSession();
		@SuppressWarnings("unchecked")
		Map<Book, Integer> cart = (Map<Book, Integer>) session.getAttribute("cart");
		Book p = new Book();
		p.setId(id);
		if (cart.get(p).intValue()!= 0) {
			int count=cart.get(p);
			cart.put(p, count);
		} else {
			cart.remove(p);
		}
		response.sendRedirect(request.getContextPath() + "/client/cart.jsp");
		return;
	}
}
